<!DOCTYPE html>
<html>
<head>
    <title>交警罚没</title>
    <#include "../inc/header.ftl"/>
    <link rel="stylesheet" href="${prefix}/assets/custom/css/main.css"/>
</head>
<body>

<div class="main-container ace-save-state" id="main-container">

    <div class="main-content">
        <div class="main-content-inner">

            <div class="page-content">
                <form id="illegalactivityForm" name="illegalactivityForm" action="illegalactivityview" method="post">
                    <table width="900" border="0" align="center" cellpadding="0" cellspacing="0" class="r_tablebr">
                        <tr>
                            <td valign="top" class="r_nr">
                                <table width="99%" border="0" cellpadding="0" cellspacing="0" class="r_zsdwbm">
                                    <tr>
                                        <td align="left"><b>处罚决定书号</b>
                                            <input name="billnum" type="text" id="billnum" value="" class="r_input2"
                                                   style="width:190px;"/> <label for="select"></label></td>
                                        <td>交易流水号<input type="text" id="bankaffirm" name="bankaffirm" value=""
                                                        class="r_input2" style="width:90px;"></td>
                                    </tr>
                                </table>
                                <table width="99%" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                        <td class="r_title">公安交通管理局建议程序处罚决定书</td>
                                    </tr>
                                </table>
                                <table width="99%" border="1" cellpadding="0" cellspacing="0" class="r_zsdwbm">
                                    <tr>
                                        <td width="50%" align="left">银行账号：
                                            <input name="accountcode" type="text" id="accountcode" style="width:250px"
                                                   readonly="readonly" class="r_input"/></td>
                                        <td width="50%" align="left">账户名称：
                                            <input name="accountname" type="text" id="accountname" style="width:250px"
                                                   readonly="readonly" class="r_input"/></td>
                                    </tr>
                                </table>
                                <table width="99%" border="1" cellpadding="0" cellspacing="1" class="r_jcxx4">
                                    <tr>
                                        <td width="115" align="center" bgcolor="#f0f0f0">被处罚人</td>
                                        <td align="center" bgcolor="#f0f0f0"><input name="occurname" type="text"
                                                                                    id="occurname" style="width:210px;"
                                                                                    readonly="readonly" class="r_input"
                                                                                    value=""/></td>
                                        <td width="110" align="center" bgcolor="#f0f0f0">驾驶证号</td>
                                        <td align="center" bgcolor="#f0f0f0"><input name="certificatenum" type="text"
                                                                                    id="certificatenum"
                                                                                    style="width:210px;"
                                                                                    readonly="readonly" value=""
                                                                                    class="r_input"/></td>
                                    </tr>
                                    <tr>
                                        <td align="center" bgcolor="#f0f0f0">违法时间</td>
                                        <td align="center" bgcolor="#f0f0f0"><input name="occurdatetime" type="text"
                                                                                    id="occurdatetime"
                                                                                    style="width:210px;"
                                                                                    readonly="readonly" value=""
                                                                                    class="r_input"/></td>
                                        <td align="center" bgcolor="#f0f0f0">处理时间</td>
                                        <td align="center" bgcolor="#f0f0f0"><input name="opterdatetime" type="text"
                                                                                    id="opterdatetime"
                                                                                    style="width:210px;"
                                                                                    readonly="readonly" value=""
                                                                                    class="r_input"/></td>
                                   </tr>
                                </table>
                                <table width="99%" 1="0" cellpadding="0" cellspacing="1" class="r_jcxx4" id="tab">
                                    <tr>
                                        <td width="115" align="center" bgcolor="#f0f0f0">违法编码</td>
                                        <td width="265" align="center" bgcolor="#f0f0f0">违法行为</td>
                                        <td align="center" bgcolor="#f0f0f0">违法描述</td>
                                    </tr>
                                    <tr id="tab-tr1">
                                        <td align="center" bgcolor="#f0f0f0"></td>
                                        <td align="center" bgcolor="#f0f0f0"></td>
                                        <td align="center" bgcolor="#f0f0f0"></td>
                                    </tr>
                                    <tr id="tab-tr2">
                                        <td align="center" bgcolor="#f0f0f0"></td>
                                        <td align="center" bgcolor="#f0f0f0"></td>
                                        <td align="center" bgcolor="#f0f0f0"></td>
                                    </tr>
                                </table>
                                <table width="99%" border="1" cellpadding="0" cellspacing="1" class="r_jcxx4">
                                    <tr>
                                        <td width="100" align="center" bgcolor="#f0f0f0">处罚金额</td>
                                        <td width="100" align="center" bgcolor="#f0f0f0"><input name="funds" type="text"
                                                                                                id="funds"
                                                                                                style="width:80px;"
                                                                                                readonly="readonly"
                                                                                                value=""
                                                                                                class="r_input"/></td>
                                        <td width="100" align="center" bgcolor="#f0f0f0">滞纳金</td>
                                        <td width="100" align="center" bgcolor="#f0f0f0"><input name="latefee"
                                                                                                type="text" id="latefee"
                                                                                                style="width:80px;"
                                                                                                readonly="readonly"
                                                                                                value=""
                                                                                                class="r_input"/></td>
                                        <td width="110" align="center" bgcolor="#f0f0f0">合　　计</td>
                                        <td width="478" colspan="3" align="center" bgcolor="#f0f0f0">
                                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                <tr>
                                                    <td width="50%" bgcolor="#FFFFFF">（大写）<span id="vbigfunds"></span>
                                                    </td>
                                                    <td width="50%" bgcolor="#FFFFFF">（小写）<span id="vfunds"></span></td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                                <table width="99%" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                        <td width="50%" align="left">付款方式
                                            <input name="paywaycode" type="text" id="paywaycode" class="r_input2" style="width:80px"/></td>
                                        <td height="40" align="right">
                                            <input type="button" name="button" id="button" class="r_button" onclick="queryIllegalactivityData()" value="查询单据" />
                                            <input type="button" name="paybutton" id="paybutton"  class="r_button" onclick="pay()" value="付款" />
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </form>
            </div><!-- /.page-content -->

        </div>
    </div><!-- /.main-content -->
</div><!-- /.main-container -->

<#include "../inc/basicjs.ftl"/>
<!-- basic scripts -->
<script src="${prefix}/assets/custom/js/commonview.js"></script>

<script type="text/javascript">

    //缴款方式下拉框
    $('#paywaycode').combobox({
        url:prefix + '/base/basedata/findPayWay',
        valueField:'paywayid',
        textField:'paywayname',
        panelHeight:'auto',
        onLoadSuccess:function(){
            var data = $('#paywaycode').combobox('getData');//获取所有下拉框数据
            if (data.length > 0) {
                //如果有数据的话默认选中第一条数据
                $('#paywaycode').combobox('select',data[0].paywayid);
            }
        }
    });

    function pay()
    {
        if(!ischeck)
        {
            alert("请先输入处罚决定书号，然后查询单据后再点击收款！");
            $("#billnum").focus();
            ischeck = false;
            return;
        }
        $('#illegalactivityForm').form({
            url: prefix+ '/view/illegalactivity/illegalactivitypayview',
            onSubmit:function(){
                var isValid = $(this).form('validate');
                return isValid;
            },
            success:function(data) {
                var data = eval('(' + data + ')');
                if (data.success) {
                    $('#ChargeBillForm').form('clear');
                    location=prefix+'/view/illegalactivity/illegalactivityview';
                }
                alert(data.msg);
            }
        });
        $('#illegalactivityForm').submit();
    }
    //加法函数，用来得到精确的加法结果
    //说明:javascript的加法结果会有误差，在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。
    //调用:accAdd(arg1,arg2)
    //返回值:arg1加上arg2的精确结果
    function accAdd(arg1,arg2){
        var r1,r2,m;
        try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
        try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
        m=Math.pow(10,Math.max(r1,r2))
        return (arg1*m+arg2*m)/m
    }

    //给Number类型增加一个add方法，调用起来更加方便。
    Number.prototype.add = function (arg){
        return accAdd(arg,this);
    }
    function queryIllegalactivityData() {
        var state = [{"key":"0","value":"查询错误"},{"key":"1","value":"正常"},{"key":"2","value":"未配置本银行账户"},{"key":"3","value":"已收款"},{"key":"4","value":"票据不存在"},{"key":"5","value":"对账不成功，账户停用"}];
        var billnum = $("#billnum").val();
        if(billnum=="" || billnum.length!=15) {
            alert("请输入正确的处罚决定书号！");
            $("#billnum").focus();
            return;
        }
        $.ajax({
            type: "POST",
            url:  prefix+"/view/illegalactivity/querystudentview",
            dataType: "json",
            data: { billnum: billnum},
            success: function (dataOne) {
                $.messager.progress('close');
                if (!dataOne.success) {
                    $.messager.alert('提示', dataOne.msg, 'info');
                    return;
                }

                var bill = dataOne.data;
                if (bill.billstate == 3 || bill.billstate == 1) {
                    $("#billnum").val(bill.billnum);
                    $("#accountname").val(bill.accountname);
                    $("#accountcode").val(bill.accountcode);
                    $("#occurname").val(bill.occurname);
                    $("#certificatenum").val(bill.certificatenum);
                    $("#occurdatetime").val(bill.occurdatetime);
                    $("#opterdatetime").val(bill.opterdatetime);
                    $("#funds").val(bill.funds);
                    $("#latefee").val(bill.latefee);

                    var funds = Number(bill.funds);
                    var latefee = Number(bill.latefee);
                    var vfunds = funds + latefee;
                    var vbigfunds = upDigit(vfunds);
                    $("#vfunds").html(vfunds);
                    $("#vbigfunds").html(vbigfunds);

                    var details_length = bill.detailVOS.length;
                    if (details_length > 0) {
                        $("#tab-tr1").remove();
                        $("#tab-tr2").remove();
                        var rownum = 0;
                        var $tr = $("#tab tr:last");
                        var strhtml = "";

                        bill.detailVOS.forEach(function (detail) {
                            var occurcode = detail.occurcode;
                            var actions = detail.actions;
                            var actionscontent = detail.actionscontent;
                            strhtml = '<tr id="tab-tr' + (rownum + 1) + '"><td align="center" bgcolor="#f0f0f0">' + occurcode + '</td><td align="center" bgcolor="#f0f0f0">' + actions + '</td><td align="center" bgcolor="#f0f0f0" style="word-wrap:break-word">' + actionscontent + '</td></tr>';
                            $tr.after(strhtml);
                            rownum++;
                            $tr = $("#tab tr:last");
                        });

                        while (rownum < 2) {
                            strhtml = '<tr id="tab-tr' + (rownum + 1) + '"><td align="center" bgcolor="#f0f0f0">&nbsp;</td><td align="center" bgcolor="#f0f0f0">&nbsp;</td><td  align="center" bgcolor="#f0f0f0">&nbsp;</td></tr>';
                            $tr.after(strhtml);
                            rownum++;
                            $tr = $("#tab tr:last");
                        }
                    }
                }

                if (bill.billstate == 1) {
                    $('#paybutton').attr('disabled', false);
                    $('#billnum').attr("readonly", "readonly");
                    ischeck = true;
                } else {
                    $('#paybutton').attr('disabled', true);
                    $.messager.alert('提示', dataOne.msgExt, 'info');
                }
            }

        })
    }
</script>


</body>
</html>